<template>
  <div class="address-view">
    <van-nav-bar left-arrow title="选择配送地址" @click-left="router.back()" />
    <van-address-list v-model="addressId" :list="userStore.Address" default-tag-text="默认" @add="onAdd" @edit="onEdit"
      @select="onSelect" />
  </div>
</template>

<script setup lang="ts">
// 引入
import { useUserStore } from '../store';
import { getAddressData } from '../api';
import { AddressListAddress } from 'vant';
// 创建实例
const userStore = useUserStore();
const router = useRouter();

let addressId = ref(userStore.nowAddress.id);
addressId.value = userStore.nowAddress.id
// 初始化地址数据
userStore.getAddress({ status: "getAddress", userId: localStorage.getItem("token") });
// 切换地址后触发
let onSelect = async (item: AddressListAddress) => {
  await getAddressData({
    status: "activeAddress", userId: localStorage.getItem("token"), addressId: item.id
  })
  router.push("/submitOrder")
}


const onAdd = () => {
  router.push("/addressEdit");
};
const onEdit = () => {

};

</script>

<style scoped></style>: any: any
